package menu.sys

import com.google.gson.Gson
import com.google.gson.JsonObject
import com.google.gson.JsonParser
import org.apache.commons.io.FileUtils
import org.junit.Test
import java.io.File

/**
 * @author futao
 * Created on 2017/12/8 - 10:12.
 */
class Test4 {
    @Test
    fun testCase001() {
        val menuObj = JsonParser().parse(FileUtils.readFileToString(File("C:\\Users\\11851\\Desktop\\menu.json"))).asJsonObject
        val oldRoleObj = JsonParser().parse(FileUtils.readFileToString(File("C:\\Users\\11851\\Desktop\\role.json"))).asJsonObject
        val newRoleObj = JsonObject()
        menuObj.entrySet().forEach { (menu_nav_k, menu_nav_v) ->
            val new_role_nav_v = JsonObject()
            newRoleObj.add(menu_nav_k, new_role_nav_v)
            val menu_nav_menu = menu_nav_v.asJsonObject.getAsJsonObject("menu")
            val new_role_nav_menu = JsonObject().apply {
                add("name", menu_nav_menu.get("name"))
                add("title", menu_nav_menu.get("title"))
                add("nav", menu_nav_menu.get("nav"))
                menu_nav_menu.get("roleType")?.let { add("roleType", it) }
            }
            new_role_nav_v.add("menu", new_role_nav_menu)

            val menu_nav_menuMap = menu_nav_v.asJsonObject.getAsJsonObject("menuMap")
            val new_role_nav_menuMap = JsonObject()
            menu_nav_menuMap.entrySet().forEach { (menu_nav_menuMap_content_k, menu_nav_menuMap_content_v) ->
                val new_role_nav_menuMap_content = JsonObject().apply {
                    add("id", menu_nav_menuMap_content_v.asJsonObject.get("id"))
                    add("title", menu_nav_menuMap_content_v.asJsonObject.get("title"))
                    add("hide", menu_nav_menuMap_content_v.asJsonObject.get("hide"))
                    menu_nav_menuMap_content_v.asJsonObject.get("roleType")?.let { add("roleType", it) }
                    menu_nav_menuMap_content_v.asJsonObject.get("line")?.let { add("line", it) }
                    menu_nav_menuMap_content_v.asJsonObject.get("style")?.let { add("style", it) }
                    menu_nav_menuMap_content_v.asJsonObject.get("icon")?.let { add("icon", it) }
                    /*ctrl*/
                    menu_nav_menuMap_content_v.asJsonObject.get("ctrl")?.let {
                        
                    }


                }
                new_role_nav_menuMap.add(menu_nav_menuMap_content_k, new_role_nav_menuMap_content)

            }

            new_role_nav_v.add("menuMap", new_role_nav_menuMap)
        }

        FileUtils.writeStringToFile(File("C:\\Users\\11851\\Desktop\\newRole.json"), Gson().toJson(newRoleObj), "utf-8")
    }
}